package com.dinzeer.slashblade_useful_addon.data;

import com.dinzeer.slashblade_useful_addon.register.SUABlock;
import com.dinzeer.slashblade_useful_addon.register.SUAItem;
import com.tterrag.registrate.providers.RegistrateRecipeProvider;
import com.tterrag.registrate.util.DataIngredient;
import mods.flammpfeil.slashblade.init.SBItems;
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.ShapedRecipeBuilder;
import net.minecraft.data.recipes.SimpleCookingRecipeBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;

import java.util.function.BiFunction;

import static com.dinzeer.slashblade_useful_addon.Slashblade_useful_addon.MODID;

public class SuaRecipeGen {
    public static void onRecipeGen(RegistrateRecipeProvider pvd) {
        unlock(pvd, ShapedRecipeBuilder.shaped(RecipeCategory.MISC,
                SUAItem.god_soul_crystal, 1)::unlockedBy, Items.IRON_INGOT)
                .pattern("AAA")
                .pattern("AAA")
                .pattern("AAA")
                .define('A', SUAItem.soul_crystal)
                .save(pvd);
        SimpleCookingRecipeBuilder.smelting(
                Ingredient.of(SUABlock.proud_soul_leaves),
                RecipeCategory.MISC,
                SBItems.proudsoul_tiny,
                0.7f,
                200
        ).unlockedBy(
                "proud_soul_by_proud_soul_leaves",
                RegistrateRecipeProvider.has( SBItems.proudsoul_tiny)
        ).save(pvd, new ResourceLocation(MODID, "proud_soul_by_proud_soul_leaves"));
        SimpleCookingRecipeBuilder.smelting(
                Ingredient.of(SUABlock.proud_soul_log),
                RecipeCategory.MISC,
                SBItems.proudsoul,
                0.7f,
                200
        ).unlockedBy(
                "proud_soul_by_proud_soul_log",
                RegistrateRecipeProvider.has( SBItems.proudsoul)
        ).save(pvd, new ResourceLocation(MODID, "proud_soul_by_proud_soul_log"));
    }
    public static <T> T unlock(RegistrateRecipeProvider pvd, BiFunction<String, InventoryChangeTrigger.TriggerInstance, T> func, Item item) {
        return func.apply("has_" + pvd.safeName(item), DataIngredient.items(item).getCritereon(pvd));
    }
}
